<?php

namespace app\api\controller;
use think\Db;
use app\common\service\AlipayService;
use app\common\service\WxpayService;


class Pay extends App
{
    
    public function alipay()
    {
        
		$user_id = $this->user_id;
        $order_id = input('post.order_id');
        $order_type = input('post.order_type',1);//1购买课程2购物服务
        $source = input('post.source',0);//0手机1pc
		
		$date_return = AlipayService::pay($order_id,$order_type,$user_id,$source);
		
		if($date_return['code'] == 1){
			return $this->show(1,"success", $date_return['data']);
		}else{
			return $this->show(2002,$date_return['msg'], '');
		}
		
    } 
	
	public function wxpay()
    {
        
        $user_id = $this->user_id;
        $order_id = input('post.order_id');
        $order_type = input('post.order_type',1);
        $source = input('post.source',0);
		
		//if($is_app == 1){
		//	$date_return = WxpayService::appwxpay($order_id,$type,$user_id,$source);
		//}else{
		//	
		//}
		$date_return = WxpayService::wechatpay($order_id,$order_type,$user_id,$source);		
		if($date_return['code'] == 1){
			return $this->show(1,"success", $date_return['data']);
		}else{
			return $this->show(2002,$date_return['msg'], '');
		}
		
    } 
    
    public function is_pay(){
		$order_id = input('post.order_id');
		if(empty($order_id)){
			return $this->show(2001,"缺少参数order_id", '');
		}
        
		$info = Db::name('course_order')->where('id',$order_id)->field('is_pay')->find();
		if(empty($info)){
			return $this->show(2001,"订单不存在", '');
		}
		$return_data = ['is_pay'=>$info['is_pay']];
		return $this->show(1,"success", $return_data);
	}
}
